文章目录
  1. 1. 基路径的使用问题
    1. 1.1. 在jsp中使用基路径base href
    2. 1.2. 不使用base href
      1. 1.2.1.
    3. 1.3.

基路径的使用问题

在jsp中使用基路径base href

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%
String path = request.getContextPath();//项目的发布路径,例如: /rabc
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<title>欢迎使用路人丁OA</title>
</head>
<body>
<a href="test">测试</a>
</body>

a标签中的路径 href=”test” 则访问 http://localhost:8080/动态获取项目名/test

​ 推荐使用

a标签中的路径 href=”/test” 则访问 http://localhost:8080/test

不使用base href

a标签中的路径 href=”test” 则访问 当前路径的相对路径

​ 例如当前路径 http://localhost:8080/项目名/duty/duty.html

​ 则访问 http://localhost:8080/项目名/duty/test

因此该种方式不推荐使用

a标签中的路径 href=”/test” 则访问 http://localhost:8080/test

在项目直接部署在根路径下可以使用,即不使用项目名

文章目录
  1. 1. 基路径的使用问题
    1. 1.1. 在jsp中使用基路径base href
    2. 1.2. 不使用base href
      1. 1.2.1.
    3. 1.3.